

package View;

import Control.ctrPrincipal;
import java.awt.GraphicsEnvironment;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.text.MaskFormatter;

public class limPrincipal extends javax.swing.JFrame {

    private ctrPrincipal control;
    private MaskFormatter maskDATA;
    
    public limPrincipal(ctrPrincipal control) {        
        this.control = control;        
        initComponents();
        setResizable(false);
        setVisible(true);
        //Centraliza janela
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        int x = ge.getCenterPoint().x - (this.getWidth()/2);
        int y = ge.getCenterPoint().y - (this.getHeight()/2);
        setLocation(x, y);
        this.setDefaultLookAndFeelDecorated(true);

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        botao_cliente_animal = new javax.swing.JButton();
        botao_produto = new javax.swing.JButton();
        botao_vendas = new javax.swing.JButton();
        label_logo = new javax.swing.JLabel();
        scrollPanel_table = new javax.swing.JScrollPane();
        table_agenda = new javax.swing.JTable();
        botao_reserva = new java.awt.Button();
        try {
            maskDATA = new MaskFormatter("##/##/####");
        }
        catch (Exception ex){
            System.out.println("Erro ao setar máscara no field_data do limPrincipal.");
        }
        field_data = new JFormattedTextField(maskDATA);
        label_data = new javax.swing.JLabel();
        botao_pesquisa = new javax.swing.JButton();
        label_lembrete = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        menu = new javax.swing.JMenuBar();
        menu_cadastros = new javax.swing.JMenu();
        menuItem_cliente_animal = new javax.swing.JMenuItem();
        menuItem_produto = new javax.swing.JMenuItem();
        menuItem_funcionario = new javax.swing.JMenuItem();
        menuItem_fornecedor = new javax.swing.JMenuItem();
        menu_vendas = new javax.swing.JMenu();
        menuItem_venda = new javax.swing.JMenuItem();
        menu_reserva = new javax.swing.JMenu();
        menuItem_reserva = new javax.swing.JMenuItem();
        menu_relatorios = new javax.swing.JMenu();
        menuItem_relatorio_venda = new javax.swing.JMenuItem();
        menuItem_relatorio_servico = new javax.swing.JMenuItem();
        menuItem_operacional = new javax.swing.JMenu();
        menuItem_backup = new javax.swing.JMenuItem();
        menu_sair = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SISPET");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        botao_cliente_animal.setFont(new java.awt.Font("Tahoma", 1, 12));
        botao_cliente_animal.setMnemonic('C');
        botao_cliente_animal.setText("Clientes/Animais");
        botao_cliente_animal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_cliente_animalActionPerformed(evt);
            }
        });

        botao_produto.setFont(new java.awt.Font("Tahoma", 1, 12));
        botao_produto.setMnemonic('P');
        botao_produto.setText("Produtos");
        botao_produto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_produtoActionPerformed(evt);
            }
        });

        botao_vendas.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        botao_vendas.setMnemonic('V');
        botao_vendas.setText("Vendas");
        botao_vendas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_vendasActionPerformed(evt);
            }
        });

        label_logo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/cabecalho.png"))); // NOI18N

        table_agenda.setFont(new java.awt.Font("Tahoma", 1, 11));
        table_agenda.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Horário", "Cliente", "Animal", "Tipo do Serviço", "Raça", "Status", "Porte", "Espécie", "Telefone", "Data"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        table_agenda.setColumnSelectionAllowed(true);
        scrollPanel_table.setViewportView(table_agenda);
        table_agenda.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);

        botao_reserva.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        botao_reserva.setLabel("Reservar horário");
        botao_reserva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botao_reservaActionPerformed(evt);
            }
        });

        label_data.setFont(new java.awt.Font("Tahoma", 0, 12));
        label_data.setText("Busca por data:");

        botao_pesquisa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/lupa.png"))); // NOI18N

        label_lembrete.setFont(new java.awt.Font("Tahoma", 1, 11));
        label_lembrete.setText("Avisos");

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setPreferredSize(new java.awt.Dimension(120, 80));
        jScrollPane1.setViewportView(jTextArea1);

        menu_cadastros.setMnemonic('A');
        menu_cadastros.setText("Cadastros");

        menuItem_cliente_animal.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.SHIFT_MASK));
        menuItem_cliente_animal.setText("Clientes e Animais");
        menuItem_cliente_animal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItem_cliente_animalActionPerformed(evt);
            }
        });
        menu_cadastros.add(menuItem_cliente_animal);

        menuItem_produto.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.SHIFT_MASK));
        menuItem_produto.setText("Produtos");
        menuItem_produto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItem_produtoActionPerformed(evt);
            }
        });
        menu_cadastros.add(menuItem_produto);

        menuItem_funcionario.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.SHIFT_MASK));
        menuItem_funcionario.setText("Funcionários");
        menuItem_funcionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItem_funcionarioActionPerformed(evt);
            }
        });
        menu_cadastros.add(menuItem_funcionario);

        menuItem_fornecedor.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.SHIFT_MASK));
        menuItem_fornecedor.setText("Fornecedores");
        menuItem_fornecedor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItem_fornecedorActionPerformed(evt);
            }
        });
        menu_cadastros.add(menuItem_fornecedor);

        menu.add(menu_cadastros);

        menu_vendas.setMnemonic('D');
        menu_vendas.setText("Vendas");

        menuItem_venda.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.SHIFT_MASK));
        menuItem_venda.setText("Realizar venda");
        menuItem_venda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItem_vendaActionPerformed(evt);
            }
        });
        menu_vendas.add(menuItem_venda);

        menu.add(menu_vendas);

        menu_reserva.setMnemonic('D');
        menu_reserva.setText("Reservas");

        menuItem_reserva.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.SHIFT_MASK));
        menuItem_reserva.setText("Realizar reserva");
        menuItem_reserva.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItem_reservaActionPerformed(evt);
            }
        });
        menu_reserva.add(menuItem_reserva);

        menu.add(menu_reserva);

        menu_relatorios.setMnemonic('E');
        menu_relatorios.setText("Relatórios");

        menuItem_relatorio_venda.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.SHIFT_MASK));
        menuItem_relatorio_venda.setText("Relatório de vendas");
        menu_relatorios.add(menuItem_relatorio_venda);

        menuItem_relatorio_servico.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.SHIFT_MASK));
        menuItem_relatorio_servico.setText("Relatório de serviços");
        menu_relatorios.add(menuItem_relatorio_servico);

        menu.add(menu_relatorios);

        menuItem_operacional.setMnemonic('O');
        menuItem_operacional.setText("Operacional");
        menuItem_operacional.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItem_operacionalActionPerformed(evt);
            }
        });

        menuItem_backup.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.SHIFT_MASK));
        menuItem_backup.setText("Backup");
        menuItem_operacional.add(menuItem_backup);

        menu.add(menuItem_operacional);

        menu_sair.setMnemonic('S');
        menu_sair.setText("Sair");
        menu_sair.addMenuListener(new javax.swing.event.MenuListener() {
            public void menuCanceled(javax.swing.event.MenuEvent evt) {
            }
            public void menuDeselected(javax.swing.event.MenuEvent evt) {
            }
            public void menuSelected(javax.swing.event.MenuEvent evt) {
                menu_sairMenuSelected(evt);
            }
        });
        menu.add(menu_sair);

        setJMenuBar(menu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(botao_reserva, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 307, Short.MAX_VALUE)
                        .addComponent(label_data)
                        .addGap(18, 18, 18)
                        .addComponent(field_data, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(botao_pesquisa)
                        .addGap(66, 66, 66))
                    .addComponent(scrollPanel_table, javax.swing.GroupLayout.PREFERRED_SIZE, 782, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(15, 15, 15)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(botao_produto, 0, 0, Short.MAX_VALUE)
                                .addComponent(botao_cliente_animal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(botao_vendas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(label_lembrete))
                .addGap(45, 45, 45))
            .addComponent(label_logo, javax.swing.GroupLayout.DEFAULT_SIZE, 1064, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(label_logo)
                .addGap(71, 71, 71)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(botao_reserva, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(11, 11, 11))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(botao_pesquisa)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(label_data)
                                        .addComponent(field_data)))
                                .addGap(20, 20, 20)))
                        .addGap(15, 15, 15)
                        .addComponent(scrollPanel_table, javax.swing.GroupLayout.PREFERRED_SIZE, 322, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(botao_vendas, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(botao_cliente_animal, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(botao_produto, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(86, 86, 86)
                        .addComponent(label_lembrete)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(76, 76, 76))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-1064)/2, (screenSize.height-662)/2, 1064, 662);
    }// </editor-fold>//GEN-END:initComponents
    private void botao_cliente_animalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_cliente_animalActionPerformed
        try {
            control.chamaCliente();
        } catch (Exception ex) {
            
        }
    }//GEN-LAST:event_botao_cliente_animalActionPerformed

    private void botao_produtoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_produtoActionPerformed
        control.chamaProduto();
    }//GEN-LAST:event_botao_produtoActionPerformed

    private void menu_sairMenuSelected(javax.swing.event.MenuEvent evt) {//GEN-FIRST:event_menu_sairMenuSelected
        this.fechar();
    }//GEN-LAST:event_menu_sairMenuSelected

    private void menuItem_cliente_animalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItem_cliente_animalActionPerformed
        try {
            control.chamaCliente();
        } catch (Exception ex) {
            
        }
    }//GEN-LAST:event_menuItem_cliente_animalActionPerformed

    private void menuItem_fornecedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItem_fornecedorActionPerformed
        control.chamaFornecedor();
    }//GEN-LAST:event_menuItem_fornecedorActionPerformed

    private void menuItem_produtoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItem_produtoActionPerformed
        control.chamaProduto();
    }//GEN-LAST:event_menuItem_produtoActionPerformed

    private void menuItem_operacionalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItem_operacionalActionPerformed
    
    }//GEN-LAST:event_menuItem_operacionalActionPerformed

    private void botao_reservaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_reservaActionPerformed
        control.chamaReserva();
    }//GEN-LAST:event_botao_reservaActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        this.fechar();
    }//GEN-LAST:event_formWindowClosing

    private void menuItem_funcionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItem_funcionarioActionPerformed
        control.chamaFuncionario();
    }//GEN-LAST:event_menuItem_funcionarioActionPerformed

    private void botao_vendasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botao_vendasActionPerformed
        control.chamaVenda();
    }//GEN-LAST:event_botao_vendasActionPerformed

    private void menuItem_vendaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItem_vendaActionPerformed
        control.chamaVenda();
    }//GEN-LAST:event_menuItem_vendaActionPerformed

    private void menuItem_reservaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItem_reservaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_menuItem_reservaActionPerformed

    public void fechar(){
        int opcao = JOptionPane.showConfirmDialog(null,"Tem certeza que deseja sair?",
                "Confirmação de encerramento", JOptionPane.YES_NO_OPTION);
        control.fechar(opcao);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botao_cliente_animal;
    private javax.swing.JButton botao_pesquisa;
    private javax.swing.JButton botao_produto;
    private java.awt.Button botao_reserva;
    private javax.swing.JButton botao_vendas;
    private javax.swing.JFormattedTextField field_data;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JLabel label_data;
    private javax.swing.JLabel label_lembrete;
    private javax.swing.JLabel label_logo;
    private javax.swing.JMenuBar menu;
    private javax.swing.JMenuItem menuItem_backup;
    private javax.swing.JMenuItem menuItem_cliente_animal;
    private javax.swing.JMenuItem menuItem_fornecedor;
    private javax.swing.JMenuItem menuItem_funcionario;
    private javax.swing.JMenu menuItem_operacional;
    private javax.swing.JMenuItem menuItem_produto;
    private javax.swing.JMenuItem menuItem_relatorio_servico;
    private javax.swing.JMenuItem menuItem_relatorio_venda;
    private javax.swing.JMenuItem menuItem_reserva;
    private javax.swing.JMenuItem menuItem_venda;
    private javax.swing.JMenu menu_cadastros;
    private javax.swing.JMenu menu_relatorios;
    private javax.swing.JMenu menu_reserva;
    private javax.swing.JMenu menu_sair;
    private javax.swing.JMenu menu_vendas;
    private javax.swing.JScrollPane scrollPanel_table;
    private javax.swing.JTable table_agenda;
    // End of variables declaration//GEN-END:variables

}
